import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
//有一个子widget的可滚动的widget，子内容超过父容器时可以滚动。
class SingleChildScrollViewEx extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('SingleChildScrollView'),),
      body: DefaultTextStyle(style: Theme.of(context).textTheme.bodyText2!,
        child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints){
          return SingleChildScrollView(
            child: ConstrainedBox(constraints: BoxConstraints(minHeight: constraints.maxHeight),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Container(
                    color: const Color(0xffeeee00),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Height Content'),
                  ),
                  Container(
                    color: const Color(0xff008000),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Heigth Content'),
                  ),
                  Container(
                    color: const Color(0xff008000),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Heigth Content'),
                  ),
                  Container(
                    color: const Color(0xff008000),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Heigth Content'),
                  ),
                  Container(
                    color: const Color(0xff008000),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Heigth Content'),
                  ),
                  Container(
                    color: const Color(0xff008000),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Heigth Content'),
                  ),
                ],
              ),
            ),
          );
        }),
      ),
    );
  }
}

class SingleChildScrollViewEx1 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(style: Theme.of(context).textTheme.bodyText2!,
        child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints){
          return SingleChildScrollView(
            child: ConstrainedBox(constraints: BoxConstraints(minHeight: constraints.maxHeight),
            child: IntrinsicHeight(
              child: Column(
                children: [
                  Container(
                    color: const Color(0xffeeee00),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Fixed Height Content'),
                  ),


                  Expanded(child: Container(
                    color: const Color(0xffee0000),
                    height: 120.0,
                    alignment: Alignment.center,
                    child: const Text('Flexible Content'),
                  ))
                ],
              ),
            ),),
          );
        }));
  }
}
